package org.nulldevice.tankshot;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class GameKeyListener extends KeyAdapter {

	Game game;

	public GameKeyListener(Game g) {
		game = g;
	}

	public void keyPressed(KeyEvent e) {
		// System.out.println("Pressed KeyCode: " + e.getKeyCode());

		switch (e.getKeyCode()) {

		case 37: // LEFT
			game.setPlayerDirection(game.getPlayerDirection()
					| game.DIRECTION_LEFT);
			break;

		case 38: // UP
			game.setPlayerDirection(game.getPlayerDirection()
					| game.DIRECTION_UP);
			break;

		case 39: // RIGHT
			game.setPlayerDirection(game.getPlayerDirection()
					| game.DIRECTION_RIGHT);
			break;

		case 40: // DOWN
			game.setPlayerDirection(game.getPlayerDirection()
					| game.DIRECTION_DOWN);
			break;

		default:
			break;
		}
	}

	public void keyReleased(KeyEvent e) {
		// System.out.println("Released KeyCode: " + e.getKeyCode());

		switch (e.getKeyCode()) {

		case 37: // LEFT
			game.setPlayerDirection(game.getPlayerDirection()
					& ~game.DIRECTION_LEFT);
			break;

		case 38: // UP
			game.setPlayerDirection(game.getPlayerDirection()
					& ~game.DIRECTION_UP);
			break;

		case 39: // RIGHT
			game.setPlayerDirection(game.getPlayerDirection()
					& ~game.DIRECTION_RIGHT);
			break;

		case 40: // DOWN
			game.setPlayerDirection(game.getPlayerDirection()
					& ~game.DIRECTION_DOWN);
			break;

		default:
			break;
		}

	}

}
